package com.xmall.order.utils;

import com.xmall.define.dto.member.DeliveryAddressDto;
import com.xmall.define.dto.order.OrderDto;
import com.xmall.define.dto.log.RetryLogDto;
import com.xmall.order.define.dto.*;
import com.xmall.order.define.dto.platform.OrderDtoForAdmin;
import com.xmall.order.define.dto.platform.OrderDtoForFront;
import com.xmall.order.define.dto.platform.OrderItemDtoForFront;
import com.xmall.order.define.request.express.OrderExpressUpdateRequest;
import com.xmall.order.define.request.query.FrontOrderListPageQueryRequest;
import com.xmall.order.entity.*;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

public interface ConvertUtils {

    /**
     * order express
     */
    @Mapper(componentModel = "spring")
    interface ExpressModule {
        ExpressModule INSTANCE = Mappers.getMapper(ExpressModule.class);

        OrderExpressDto toDto(OrderExpress orderExpress);

        OrderExpress toEntity(OrderExpressUpdateRequest request);
    }

    /**
     * order delivery
     */
    @Mapper(componentModel = "spring")
    interface DeliveryModule {
        DeliveryModule INSTANCE = Mappers.getMapper(DeliveryModule.class);

        OrderDelivery toDelivery(DeliveryAddressDto deliveryAddressDto);
    }

    /**
     * order
     */
    @Mapper(componentModel = "spring")
    interface OrderModule {
        OrderModule INSTANCE = Mappers.getMapper(OrderModule.class);

        OrderQueryParams toQueryParams(FrontOrderListPageQueryRequest request);

        OrderDto toDto(Order order);

        OrderDtoWithCascade doToDto(OrderDo orderDo);

        List<OrderDtoWithCascade> doListToDtoList(List<OrderDo> orderDoList);

        OrderDtoForFront toFront(OrderDtoWithCascade orderDtoWithCascade);

        List<OrderDtoForAdmin> listToAdmin(List<Order> orderList);

        List<OrderDtoForFront> listToFront(List<OrderDtoWithCascade> orderDtoWithCascadeList);
    }

    /**
     * order item
     */
    @Mapper(componentModel = "spring")
    interface OrderItemModule {
        OrderItemModule INSTANCE = Mappers.getMapper(OrderItemModule.class);

        OrderItem toEntity(OrderItemDto orderItemDto);

        OrderItemDtoForFront toFront(OrderItemDto orderItemDto);
    }

    /**
     * order refund
     */
    @Mapper(componentModel = "spring")
    interface OrderRefundModule {
        OrderRefundModule INSTANCE = Mappers.getMapper(OrderRefundModule.class);

        OrderRefundHistory toHistory(OrderRefund orderRefund);

        List<OrderRefundDto> toDtoList(List<OrderRefund> orderRefundList);

        List<OrderRefundDto> historyListToDtoList(List<OrderRefundHistory> orderRefundHistoryList);
    }

    /**
     * order retry log
     */
    @Mapper(componentModel = "spring")
    interface RetryLogModule {
        RetryLogModule INSTANCE = Mappers.getMapper(RetryLogModule.class);

        RetryLogDto toDtoFromOrderCancel(OrderCancelRetryLog orderCancelRetryLog);
        RetryLogDto toDtoFromOrderPaySuccess(OrderPaySuccessRetryLog orderPaySuccessRetryLog);
        RetryLogDto toDtoFromOrderRefund(OrderRefundRetryLog orderRefundRetryLog);
    }
}
